/* eslint-disable */
import { getToken } from "@/utils/auth/user";
import { NavigationGuardNext, RouteLocationNormalized, Router } from "vue-router";
import { routeName } from "../public/constRoutes";
import { createDynamicRouteGuard } from "./dynamic";

/** 处理路由页面权限 */
export async function createPermissionGuard(
    to: RouteLocationNormalized,
    from: RouteLocationNormalized,
    next: NavigationGuardNext,
    router: Router,
) {
    const permission = await createDynamicRouteGuard(to, from, next, router);
    if (!permission) {
        console.error("不允许进入");
        return
    }
    next()
    // const isLogin = Boolean(getToken());
    // const permissions = to.meta?.permissions || [];
    // const needLogin = Boolean(to.meta?.requireAuth) || Boolean(permissions.length);

    // const action: Common.StrategyAction[] = [
    //     // 未登录 + 进入需要权限页面
    //     [
    //         !isLogin && needLogin,
    //         () => {
    //             const redirect = to.fullPath;
    //             next({ name: routeName('login'), query: { redirect } })
    //         }
    //     ]
    // ]
    // 判断登录权限
}